/*	talmud - The TALMUD roguelike
 * Copyright (C) 2012, talmud contributors
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of Version 2 of the GNU General Public License as published
 *  by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful, but WITHOUT
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *  FITNESS FOR A PARTICULAR PURPOSE. See Version 2 of the GNU General Public
 *  License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef talmud_h
#define talmud_h

#include <stdint.h>

#define BRANCHES	2
#define MAXDEPTH	40
#define DUNGEON_DEPTH	30
#define CATACOMBS_DEPTH	20
#define PLYR_FOV	10

#define delta(x)	((x > 0) ? 1 : ((x < 0) ? -1 : 0))

#define inkey		cfg.inkeys
#define plyrmon		plyr.mon
#define plyrbrnch	BRANCHDEFS[plyrmon.branch]
#define plyrdlvl	dlvls[plyrmon.branch][plyrmon.dlvl]
#define plyrtile	dtile(plyrmon.x, plyrmon.y)
#define plyrlos(x,y)	LOS_BLA(plyrmon.x, plyrmon.y, x, y)
#define plyrfov(x,y)	dfov(x, y)
#define plyreffac	((plyr.ac > 10) ? 10 : plyr.ac)
#define plyracbns	((plyr.ac > 10) ? (plyr.ac - 10) : 0)
#define plyrstrbns	((plyr.st - 10) / 2)
#define weapondef	ITEMDEFS[inv[invwielded].type]
#define weapon		inv[invwielded]
#define wielded(x)	(x == invwielded)
#define worn(x)		ItemWorn(x)
#define dtile(x,y)	plyrdlvl.tiles[(y) * DLVL_W + (x)]
#define dfov(x,y)	plyrdlvl.fov[(y) * DLVL_W + (x)]
#define dexposed(x,y)	plyrdlvl.exposed[(y) * DLVL_W + (x)]
#define monac(x)	RACEDEFS[mon[x].race].ac
#define monname(x)	RACEDEFS[mon[x].race].name
#define monterm(x)	RACEDEFS[mon[x].race].term
#define monlos(i,tx,ty)	LOS_BLA(mon[i].x, mon[i].y, tx, ty)
#define mononlvl(m)	(mon[m].branch == plyrmon.branch && mon[m].dlvl == plyrmon.dlvl)
#define itemonlvl(m)	(items[m].branch == plyrmon.branch && items[m].dlvl == plyrmon.dlvl)
#define impassable(x)	(x == T_ROCK || x == T_HARDROCK)

typedef struct branchdef_s
{
	const char *name;
	uint8_t depth;
} branchdef_t;

#include "monster.h"
#include "dlvl.h"
#include "item.h"
#include "playermanage.h"

extern player_t plyr;
extern item_t inv[INVMAX];
extern uint8_t invchar[INVMAX];
extern uint8_t invcount;
extern uint8_t invwielded;
extern item_t *items;
extern dlvl_t dlvls[BRANCHES][MAXDEPTH];
extern const branchdef_t BRANCHDEFS[BRANCHES];
extern monster_t *mon;
extern uint8_t itypeided[ID_COUNT];
extern char itypedesc[ID_COUNT][64];

char *capword(const char *word);
void GameOver(void);
void Unimp(const char *error);
void Bug(const char *error);
void AddMsg(const char *format, ...);

#endif
